<?xml version="1.0" encoding="utf-8" ?>
[#include "/WEB-INF/pages/common/taglibs.ftl"]
[#macro _script]
	<script type="text/javascript">
		var base = (function(){
			// 事件绑定
			function _addEventListeners() {
				// 一览
				$('a[act=view]').unbind('click').click(function(){
					var id = $(this).parent().attr('tval');
					[@c.url var="editUrl" value='/manage/Function_view.action' scope="page"]
					[/@c.url]
					var url = "${editUrl}?id=" + id;
					//$.get(url, {'id':id, 'ajax':'true'}, function(data) {
					//	$('#body').html(data);
					//})
					window.location = url;
				})
				
				// 删除
				$('a[act=delete]').unbind('click').click(function(){
					var id = $(this).parent().attr('tval');
					$( "#delete-confirm" ).dialog({
						resizable: false,
						height:160,
						width:260,
						modal: true,
						buttons: {
							"删除": function() {
								[@c.url var="backUrl" value='/manage/Function_list.action' scope="page"]
									[@c.param name="currentPage" value="${currentPage}"/]
								[/@c.url]
								window.location = "[@c.url value='/manage/Function_delete.action?id='/]" + id + "&backurl=${backUrl}";
								$( this ).dialog( "close" );
							},
							"取消": function() {
								$( this ).dialog( "close" );
							}
						}
					});
					$( "#delete:ui-dialog" ).dialog( "destroy" );
					return false;
				})
				
				// Create jqxExpander
        		$('.jqxExpander').jqxExpander({showArrow: false, toggleMode: 'none', height: '500px', theme: base.config.theme });
			}
			
			// 页面渲染
			function _treeRender () {
				// Create jqxTree
        		$('#jqxTree').jqxTree({height:'450px;', theme: base.config.theme });
        		$('#jqxTree').unbind().bind('select', function (event) {
	                var args = event.args.element.outerHTML;
	                var id = $('a', $(args)).attr('ckey');
					//使用一个ajax请求,去渲染body部分
					//参数注意：ajax代表是一个ajax请求;渲染本页的body,但在装饰器中为一个div体
					//所以在装饰器页里,将内容页放入不同位置,但内容页的ajax不会改变.
	                $.get(base.config.url, {'id':id, 'ajax':true, 'piece':true}, function(data){
	                	$('#functionList').html(data);
	                	_addEventListeners();
	                })
	            });
			};
			return {
                config: {
                	url : null,
                    theme: null
                },
                init: function () {
                	_addEventListeners();
                	_treeRender();
                }
			}
		}());
		
		$(function(){
			var link = "[@c.url value='/manage/Function_list.action?currentPage=${currentPage}'/]";
			base.config.theme = getTheme();
			base.config.url = link;
            //Initializing the form
			base.init();
		})
	</script>
[/#macro]
[#if piece==true]
	[@_script /]
	<!--设置提交行为-->
	[#assign act="save" /]
	<!--设置table渲染到指定ID节点-->
	[#assign renderTo="#functionList"]
	[#include "/WEB-INF/pages/manage/_functionList.ftl"]
[#else]
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Insert title here</title>
		<meta name="menu" content="AdminMenu"/>
		<meta name="heading" content="heading"/>
		<style type="text/css">
			.article {
				padding:0;
				margain:0;
			}
			.function_tree {
				width:240px;
				/*height:500px;*/
				float:left;
				margin-left:2px;
			}
			.function_list {
				/*height:500px;*/
				margin-left:248px;
			}
		</style>
		[@_script /]
	</head>
	<body id="body" class="art_content">
		<div class="article">
			<div class="function_tree">
		    	[@s.action name="Function_tree" executeResult="true" namespace="/manage"]
		    		[@s.param name="ajax" value="true" /]
		    		[@s.param name="id" value="1" /]
		    	[/@s.action]
		    </div>
		
			<div id="functionList" class="function_list">
				<!--设置提交行为-->
				[#assign act="save" /]
				<!--设置table渲染到指定ID节点-->
				[#assign renderTo="#functionList"]
				[#include "/WEB-INF/pages/manage/_functionList.ftl"]
			</div>
			<div style="clear: both;"></div>
		</div>
	</body>
	</html>
[/#if]